home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / tsr_asm.zip / IBM.C < prev    next >
C/C++ Source or Header  |  1988-08-05  |  4KB  |  190 lines

  1. #include    "va.h"
  2. #include    "vadef.h"
  3. #include    "edit.h"
  4.  
  5. #if MSDOS & LATTICE
  6.  
  7. #define    CDCGA    0            /* color graphics card        */
  8. #define    CDMONO    1            /* monochrome text card        */
  9.  
  10. /* getboard:    Determine which type of display board is attached.
  11.         Current known types include:
  12.  
  13.         CDMONO    Monochrome graphics adapter
  14.         CDCGA    Color Graphics Adapter
  15.         CDEGA    Extended graphics Adapter
  16. */
  17.  
  18. /* getboard:    Detect the current display adapter
  19.         if MONO        set to MONO
  20.            CGA        set to CGA
  21.            EGA        set to CGA
  22. */
  23.  
  24.     int boardSEG;    /* Segment of screen memory */
  25. static    int mode;    /* mode of screen image */
  26. static    int xcursor;    /* xcoord. of cursor */
  27. static    int ycursor;    /* ycoord. of cursor */
  28. static    int page;    /* display page nr */
  29. static    int curch;    /* cursor h value */
  30. static    int curcl;    /* cursor l value */
  31. static    byte screen[16384];    /* old screen */
  32. static    byte lowmem[30];    /* 0000:0449h 30 bytes video stuff */
  33.  
  34. int getboard()
  35. {    union REGS rg;
  36.  
  37.     int type;    /* board type to return */
  38.  
  39.     type = CDCGA;
  40.     int86(0x11, &rg, &rg);
  41.     if ((((rg.x.ax >> 4) & 3) == 3))
  42.         type = CDMONO;
  43.  
  44.     switch (type) {
  45.         case CDCGA:
  46.             boardSEG = 0xb800;
  47.             break;
  48.         case CDMONO:
  49.             boardSEG = 0xb000;
  50.             break;
  51.     }
  52. }/*getboard*/
  53.  
  54. getpage()
  55. {    union REGS rg;
  56.  
  57.     rg.h.ah = 0xf;
  58.     int86(0x10,&rg,&rg);    /* get current display page and mode */
  59.     page = rg.h.bh;
  60.     mode = rg.h.al;
  61. }/*getpage*/
  62.  
  63. putpage()
  64. {    union REGS rg;
  65.  
  66.     /* check mode only if diff then set */
  67.     rg.h.ah = 0xf;
  68.     int86(0x10,&rg,&rg);
  69.     if (rg.h.al == mode) {
  70.         /* nothing */
  71.     } else {
  72.         rg.h.ah = 0;
  73.         rg.h.al = mode;
  74.         int86(0x10,&rg,&rg);    /* set mode */
  75.     }
  76.  
  77.     /* set display page if different */
  78.     rg.h.ah = 0xf;
  79.     int86(0x10,&rg,&rg);
  80.     if (rg.h.bh == page) {
  81.         /* nothing */
  82.     } else {    
  83.         rg.h.ah = 0x5;
  84.         rg.h.al = page;
  85.         int86(0x10,&rg,&rg);    /* set active page */
  86.     }
  87. }/*putpage*/
  88.  
  89. putcursor()
  90. {    union REGS rg;
  91.  
  92.     rg.h.ah = 0x1;
  93.     rg.h.ch = curch;
  94.     rg.h.cl = curcl;
  95.     int86(0x10,&rg,&rg);    /* set cursor size */
  96.  
  97.     rg.h.ah = 0x2;
  98.     rg.h.bh = page;
  99.     rg.h.dh = ycursor;
  100.     rg.h.dl = xcursor;
  101.     int86(0x10,&rg,&rg);    /* set cursor position */
  102. }/*putcursor*/
  103.  
  104. getcursor()
  105. {    union REGS rg;
  106.  
  107.     rg.h.ah = 0x3;
  108.     rg.h.bh = page;
  109.     int86(0x10,&rg,&rg);    /* get cursor position and size */
  110.     curch = rg.h.ch;
  111.     curcl = rg.h.cl;
  112.     xcursor = rg.h.dl;
  113.     ycursor = rg.h.dh;
  114. }/*getcursor*/
  115.  
  116. /* getlowmem*/
  117. getlowmem()
  118. {
  119.     peek(0,0x449,lowmem,30);
  120. }/*getlowmem*/
  121.  
  122. /* putlowmem */
  123. putlowmem()
  124. {
  125.     poke(0,0x449,lowmem,30);
  126. }/*putlowmem*/
  127.  
  128. /* copy current screen into screen[] */
  129. pushscreen()
  130. {
  131.     getlowmem();
  132.     getboard();
  133.     peek(boardSEG,0,screen,16384);
  134.     getpage();    /* get display page and mode */
  135.     getcursor();
  136. }/*getscreen*/
  137.  
  138. /* fill current screen with contents of screen[] */
  139. popscreen()
  140. {
  141.     putpage();    /* put display page and mode */
  142.     putcursor();    
  143.     poke(boardSEG,0,screen,16384);
  144.     putlowmem();
  145. }/*putscreen*/
  146.  
  147. /* called from note with empty note, we must insert original screen */
  148. insscreen()
  149. {    register int    r,c;
  150.     register char *ptr,*lptr;
  151.     int    ch,len;
  152.  
  153.     switch (mode) {
  154.         case 0:
  155.         case 1:
  156.             len = 40;
  157.             break;
  158.         case 2:
  159.         case 3:
  160.         case 7:
  161.             len = 80;
  162.             break;
  163.         default:
  164.             TTbeep();
  165.             return;
  166.     }
  167.     ptr = screen;
  168.     for (r=0; r<25; r++) {
  169.         for (c=0; c<len; c++) {
  170.             ch = *ptr;
  171.             ptr += 2;
  172.             /* blank out non printables */
  173.             if (ch =='\r') ch = ' ';
  174.             if ( (ch < ' ') || (ch > '~') ) ch = ' ';
  175.             inschar(ch);
  176.         }
  177.         /* take of trailing spaces */
  178.         lptr = &(editroot->curline->line[len-1]);
  179.         for (c=len-1; c>=0; c--) {
  180.             if (*lptr != ' ') break;
  181.             (editroot->curline->length)--;
  182.             *lptr = '\0';
  183.             lptr--;
  184.         }
  185.         goeol();
  186.         inschar('\r');
  187.     }
  188. }/*insscreen*/
  189. #endif
  190.